<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="queryParams.username" placeholder="请输入用户名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="巡检点" prop="checkaddress">
        <el-input v-model="queryParams.checkaddress" placeholder="请输入巡检点" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="巡检坐标" prop="cheackcoordinate">
        <el-input v-model="queryParams.cheackcoordinate" placeholder="请输入巡检坐标" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="设备号" prop="devicenumber">
        <el-input v-model="queryParams.devicenumber" placeholder="请输入设备号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="时间范围" prop="checktime">
        <el-time-picker v-model="queryParams.checktimepicker" is-range format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" start-placeholder="开始时间" end-placeholder="结束时间"
          range-separator="至" clearable>
        </el-time-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['weixiu:weixiu:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['weixiu:weixiu:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['weixiu:weixiu:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['weixiu:weixiu:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="weixiuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户名" align="center" prop="username" />
      <el-table-column label="巡检点" align="center" prop="checkaddress" />
      <!-- <el-table-column label="巡检坐标" align="center" prop="cheackcoordinate" /> -->
      <el-table-column label="设备号" align="center" prop="devicenumber" />
      <el-table-column label="巡检类型" align="center" prop="checktype" />
      <el-table-column label="巡检时间" align="center" prop="checktime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.checktime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡检内容" align="center" prop="checkcontent" />


      <el-table-column label="巡检图片" align="center" prop="checkimage" width="100">
        <template slot-scope="scope">
          <!-- <image-preview :src="scope.row.checkimage" :width="50" :height="50"/> -->

          <el-button size="mini" type="text" icon="el-icon-edit" @click="ChaKan(scope.row)">查看图片</el-button>

        </template>
      </el-table-column>

      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />




    <el-dialog class="el-dialogs" :title="title" :visible.sync="open"   append-to-body width="800px">
      <el-image class="demo-image__lazy" v-for="(img,index) in srcList" :key="index" :src="img">
      </el-image>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
  import {
    listWeixiu,
    getWeixiu,
    delWeixiu,
    addWeixiu,
    updateWeixiu
  } from "@/api/weixiu/weixiu";

  export default {
    name: "Weixiu",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // weixiu表格数据
        weixiuList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        open1: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          username: null,
          checkaddress: null,
          cheackcoordinate: null,
          devicenumber: null,
          checktype: null,
          checktimepicker: null,
          checkcontent: null,
          checkimage: null,
          data1: null,
          data2: null,
          data3: null,
          data4: null,
          data5: null,
          data6: null,
          data7: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        srcList: [
          'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
          'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
        ]
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询weixiu列表 */
      getList() {
        this.loading = true;
        listWeixiu(this.queryParams).then(response => {
          this.weixiuList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },

      // 表单重置
      reset() {
        this.form = {
          id: null,
          username: null,
          checkaddress: null,
          cheackcoordinate: null,
          devicenumber: null,
          checktype: null,
          checktime: null,
          checkcontent: null,
          checkimage: null,
          data1: null,
          data2: null,
          data3: null,
          data4: null,
          data5: null,
          data6: null,
          data7: null
        };
         // this.queryParams. checktimepicker= null;
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加weixiu";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getWeixiu(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "查看图片";
        });
      },
      ChaKan(row) {

        if (!row.checkimage) {
          this.$message.error("暂无图片");
          return
        }
        console.log(process.env.VUE_APP_BASE_API);
        var arr = row.checkimage.split(',')

        var arr2 = arr.map((item, index, arrs) =>
          process.env.VUE_APP_BASE_API + "/profile/" + item
        );
        console.log(arr2);
        this.srcList = arr2;
        this.open = true;
        this.title = "查看图片";

      },
      submitForm2() {
        this.open = false;
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateWeixiu(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addWeixiu(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除weixiu编号为"' + ids + '"的数据项？').then(function() {
          return delWeixiu(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('weixiu/weixiu/export', {
          ...this.queryParams
        }, `weixiu_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style scoped lang="scss">

</style>
